<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div
        class="table-page-search-wrapper"
        v-if="true"
      >
        <a-form layout="inline">
          <a-row :gutter="20">
            <a-col
              :md="8"
              :sm="24"
            >
              <a-form-item label="订单时间">
                <a-range-picker
                  :format="'YYYY-MM-DD'"
                  :valueFormat="'YYYY-MM-DD'"
                  v-model="queryParam.datetime"
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="8"
              :sm="24"
            >
              <a-form-item label="店铺名称">
                <a-input
                  placeholder="请输入店铺名称"
                  v-model="queryParam.keyword"
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="8"
              :sm="24"
            >
              <span class="table-page-search-submitButtons">
                <a-button
                  type="primary"
                  @click="$refs.table.refresh(true)"
                >查询</a-button>
                <a-button
                  style="margin-left: 8px"
                  @click="resetQueryParams"
                >重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <s-table
        rowKey="id"
        size="default"
        :columns="columns"
        :data="loadData"
        ref="table"
      >
        <a-row
          slot="order_status"
          slot-scope="text, order"
        >
          <a-tag
            color="green"
            v-if="order.is_pay == 1"
          >
            已付款
          </a-tag>
          <a-tag
            color="red"
            v-if="order.is_pay == 0"
          >
            待付款
          </a-tag>
		  <a-tag
		    color="green"
		    v-if="order.trade_status == 3"
		  >
		    已收货
		  </a-tag>
		  <a-tag
		    color="red"
		    v-else-if="order.trade_status == 2"
		  >
		    待收货
		  </a-tag>
		  <a-tag
		    color="red"
		    v-if="order.trade_status == 0"
		  >
		    未发货
		  </a-tag>
          <span v-if="order.apply_delete == 1">
            <a-tag
              color="green"
              v-if="order.trade_status == 1"
            >
              申请取消成功
            </a-tag>
            <a-tag
              color="red"
              v-else
            >
              申请取消中
            </a-tag>
          </span>
        </a-row>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import {
  STable
} from '@/components'
import {
  order
} from '@/api/statistic/mch'
const columns = [
  {
    title: 'ID',
    align: 'center',
    dataIndex: 'id'
  },
  {
    title: '商户名称',
    align: 'center',
    dataIndex: 'name'
  },
  {
    title: '订单编号',
    align: 'center',
    dataIndex: 'order_no'
  },
  {
    title: '订单金额',
    align: 'center',
    dataIndex: 'pay_price'
  },
  {
    title: '商户抽佣',
    align: 'center',
    dataIndex: 'yongjin'
  },
  {
    title: '订单状态',
    align: 'center',
    width: '150',
    dataIndex: 'trade_status',
    scopedSlots: {
      customRender: 'order_status'
    }
  }
]

export default {
  name: 'SaleGoods',
  components: {
    STable
  },
  data () {
    return {
      labelCol: {
        xs: {
          span: 24
        },
        sm: {
          span: 5
        }
      },
      wrapperCol: {
        xs: {
          span: 24
        },
        sm: {
          span: 16
        }
      },
      // 表头
      columns,
      modalLoading: false,
      // 查询条件参数
      queryParam: {
        keyword: null,
        datetime: []
      },
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        Object.assign(parameter, this.queryParam)
        return order(parameter)
          .then(res => {
            console.log('order', res)
            return res.data
          }).catch(err => {
            this.$message.error(err.message)
            this.$refs.table.localLoading = false
          })
      }
    }
  },
  filters: {
  },
  created () {
  },
  methods: {
    resetQueryParams () {
      Object.assign(this.queryParam, {
        keyword: null,
        datetime: []
      })
      this.$refs.table.refresh(true)
    }
  }
}
</script>

<style lang="less" scoped>
.permission-form {
  /deep/ .permission-group {
    margin-top: 0;
    margin-bottom: 0;
  }
}
</style>
